-
Notifications
You must be signed in to change notification settings - Fork 252
Copy assets files when using mix.version() command #268
Conversation
It's somewhat common to use relative paths in .css files. Versioning such files with elixir invalidates all relative paths: http://stackoverflow.com/questions/27789466/asset-management-maintaining-reference-to-relative-assets-after-concatenation/32223524#32223524 This PR proposes a simple syntax to solve this kind of problem, by allowing users to define an array of paths relative to **/public** as a second (or third) argument, so they'll be copied to **/build** after `version` command executes. **Usage** ``` mix.version( ['css/style.css', 'css/vendor/style.css'], //files to be versioned ['fonts', 'css/vendor/icons'] //dependent files/dirs to be copied ); ``` This will also re-copy every dependent files when using `gulp watch`.
Elixir.extend('version', function(src, buildPath) { | ||
Elixir.extend('version', function(src, buildPath, assets) { | ||
// Allow users to use assets as the second argument | ||
if(Array.isArray(buildPath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cs
Sorry for my ignorance, but what does a cs mean? Computer Science? Counter Strike? Commit Sucks? =D |
code style |
OK, thanks for spotting. So what is the recommended style then? Does this project have a styleguide published somewhere? |
I mean, which is the specific issue in this case? It's something like "there are cleaner ways to detect arrays in js" or "arguments should have only one well-defined responsability, do not ever try to hook this kind of kludge!" As I think the second one is most probable, I can just remove this block (the rest will work just fine), but users would need to call all arguments on gulpfile, even if they don't want to change the build dir. I personally wouldn't mind to write |
There was a refactor from @JeffreyWay in this file on main repository before my PR was accepted. So, I solved the resulting conflicts and developed a cleaner version of the proposed feature, based on his last commit. Also, I removed the option for ommiting the second argument. While slightly handy for the end user, the implementation was not nice code.
There was a refactor from @JeffreyWay in this file on main repository before this PR was accepted. So, I solved the resulting conflicts and developed a cleaner version of the proposed feature, based on his last commit. Also, I removed the option for ommiting the second argument. While slightly handy for the end user, the implementation was not nice code. |
I'm not sure about this. Isn't it a best practice to not use relative paths in your CSS files? |
Hey Jeff, Yes, it is a bad practice and our team does not use relative paths in our controlled files. However, there are some vendors that do it, and we do not touch their codes - everything is just controlled via Bower. Things started to break since we started versioning our files. So, this PR was the solution we've found to solve the problem, while keeping a clean and readable gulpfile. We are using it in production since then. We use this third (optional) argument to copy some small files (i.e fonts and icons) used by some third-party libs that use relative paths inside their own directory structure. We could use |
I really appreciate the PR - and may merge at a later date. But it doesn't seem like anyone else needs this. And I'd prefer to keep the versioning API as simple as possible, rather than passing a special array as an arg. Thanks! |
Well... maybe a callback would be a better idea, instead of an array? That way people could implement whatever hook they need. |
It's somewhat common to use relative paths in .css files.
Versioning such files with elixir invalidates all relative paths:
http://stackoverflow.com/questions/27789466/asset-management-maintaining-reference-to-relative-assets-after-concatenation/32223524#32223524
This PR proposes a simple syntax to solve this kind of problem, by allowing users to define an array of paths relative to /public as a second (or third) argument, so they'll be copied to /build after
version
command executes.Usage
This will also re-copy every dependent files when using
gulp watch
.